# -*- coding: utf-8 -*-

import os

# Scrapy settings for ArticleSpider project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://doc.scrapy.org/en/latest/topics/settings.html
#     https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://doc.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'ArticleSpider'

SPIDER_MODULES = ['ArticleSpider.spiders']
NEWSPIDER_MODULE = 'ArticleSpider.spiders'


# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'ArticleSpider (+http://www.yourdomain.com)'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
#COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False

# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'en',
#}

# Enable or disable spider middlewares
# See https://doc.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'ArticleSpider.middlewares.ArticlespiderSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
# DOWNLOADER_MIDDLEWARES = {
#    # 'ArticleSpider.middlewares.ArticlespiderDownloaderMiddleware': 543,
#    # 'ArticleSpider.middlewares.RandomUserAgentDownloaderMiddleware': 500,
#    # 'ArticleSpider.middlewares.AutoRandomUserAgentDownloaderMiddleware': 500,
#    # 'ArticleSpider.middlewares.ConfigRandomUserAgentDownloaderMiddleware': 500,
#    # 'ArticleSpider.middlewares.SampleIntegrateSeleniumUserAgentDownloaderMiddleware': 500,
#    # 'ArticleSpider.middlewares.SampleIntegrateSeleniumUserAgentDownloaderMiddleware1': 500,
#    'ArticleSpider.middlewares.SampleIntegrateSeleniumUserAgentDownloaderMiddleware2': 500,
#
#     #禁用自带的UserAgent中间件
#    #如果不禁用，同时设置的优先级比我们的低(不是高)
#    #那么他又会更改为默认的UserAgent
#    'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
# }

# Enable or disable extensions
# See https://doc.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
   # 'ArticleSpider.pipelines.JsonExporterPipeline': 2,
   # # 'scrapy.pipelines.images.ImagesPipeline': 1, #要安装pillow库
   # 'ArticleSpider.pipelines.ArticleImagePipeline': 1,
   # 'ArticleSpider.pipelines.MySQLPipeline': 1,
   # 'ArticleSpider.pipelines.MySQLTwistedPipeline': 1,
   'ArticleSpider.pipelines.ElasticsearchPipeline': 1,

}

# 那个字段是image地址
IMAGES_URLS_FIELD="cover_image"

#是当前文件所在的目录
filepath=os.path.dirname(__file__)
print(filepath)

#是当前文件所在的目录
project_dir=os.path.abspath(os.path.dirname(__file__))

print(project_dir)

# 图片保存路径
IMAGES_STORE=os.path.join(project_dir,"images")

#最小图片宽高
# IMAGES_MIN_WIDTH=100
# IMAGES_MIN_HEIGHT=100

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'

#python源码路径设置
import os
import sys

#写绝对路径，仅供演示
# sys.path.insert(0,"/home/smile/Documents/works/person/python/ArticleSpider/ArticleSpider")

root_project_dir=os.path.dirname(project_dir)
print(root_project_dir)

article_spider_dir=os.path.join(root_project_dir,"ArticleSpider")
print(article_spider_dir)

# sys.path.insert(0,article_spider_dir)

#MySQL配置
MYSQL_HOST="127.0.0.1"
MYSQL_DATABASE="article_spider"
MYSQL_USERNAME="root"
MYSQL_PASSWORD="ixuea888"

#sql日期格式化
SQL_DATETIME_FORMAT="%Y-%m-%d %H:%M:%S"
SQL_DATE_FORMAT="%Y-%m-%d"

#user agent大全
USER_AGENTS=[
   "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.35",
   "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
]

# fake-useragent 随机生成类型
# 这是我们自定义中间的的配置
# 可选值就是该框架的值

# 所有浏览器
# TYPE_RANDOM_USER_AGENT="random"

# firefox
TYPE_RANDOM_USER_AGENT="firefox"